window.onload = function () {
    /*发送ajax动态获取章节信息*/
    $(".writeMyLi").click(function () {
        var sId = $(this).next().val();
        var LzShowLi = $(".LzShow").text();
        $.ajax({
            type: "post",
            url: "/cahpter/getChapter",
            data: {
                sId: sId
            },
            success: function (data) {

                if (data.success) {
                    var str = data.data;
                    arr1 = [];
                    str.forEach(function (v) {
                        arr1.push(v.chTitle);
                    });
                    console.log(arr1);
                    var strs = ``;
                    for (var i = 0; i < arr1.length; i++) {
                        strs += `<li>${arr1[i]}</li>`;
                    }
                    $('.LzShow').prepend(strs);
                }

            },
            error: function () {

            }

        });
    });
    // 导航部分消息为0不显示
    $(function () {
        var informationIcon = $(".informationIcon").text();
        if (informationIcon == "0") {
            $(".informationIcon").css("display", "none");
        } else {
            $(".informationIcon").css("display", "inline-block");
        }
    });
    //下载App隐藏的二维码部分
    $(".download").hover(function () {
        $(".downloadHide").toggle();
    });
    $(".downloadHide").hover(function () {
        $(".downloadHide").toggle();
    });
    //登录之后个人信息的下拉菜单部分
    $(".myselfPic").hover(function () {
        $(".myselfDownList").toggle();
    });
    $(".myselfDownList").hover(function () {
        $(".myselfDownList").toggle();
    });//连载的二级菜单
    $(".writeLz").click(function () {
        // $(".writeLzUl").slideToggle();
        $(".writeMyLzUl").hide();
        $(".writeLzNew").css({
            "background-color": "#FFFFFF",
            "color": "#000"
        });
        $(".writeLzMy").css({
            "background-color": "#FFFFFF",
            "color": "#000"
        });
    });
    //切换
    $(".writeLzNew").click(function () {
        $(window).attr("location", "/test/editor");
    });
    $(".writeWord").click(function () {
        $(".rightWrite").show();
        $(".writeLzPage").hide();
        $(".writeLzNew").css({
            "background-color": "#FFFFFF",
            "color": "#000"
        });
        $(".writeLzMy").css({
            "background-color": "#FFFFFF",
            "color": "#000"
        });
    });
    $(".writeLzMy").click(function () {
        $(".rightWrite").hide();
        $(".writeLzPage").hide();
        $(".writeMyLzUl").slideToggle();
        $(".writeLzMy").css({
            "background-color": "#DD514C",
            "color": "#FFFFFF"
        });
        $(".writeLzNew").css({
            "background-color": "#FFFFFF",
            "color": "#000"
        });
    });
    //连载章节的切换
    $(".writeMyLi").hover(function () {
        $(".LzShow").toggle();
    });
    $(".LzShow").hover(function () {
        $(".LzShow").toggle();
    });

    //写连载章节
    $(".writeMyLzName2input").bind("input propertychange", function (event) {
        console.log($(".writeMyLzName2input").val());
    });
    $(".writeMyLzName2input").keyup(function () {
        if ($(".writeMyLzName2input").val().length > 20) {
            $(".writeMyLzName2input").val($(".writeMyLzName2input").val().substring(0, 20));
        }
        $("#word").text(20 - $(".writeMyLzName2input").val().length);
    });

    //提交连载章节
    $(".sure").click(function () {
        var writeMyLzName2input = $(".writeMyLzName2input").val();
        var ch_number = $(".chapterNumber").val();
        var sId = $(".sId").val();
        var bAddress = editor2.txt.html();
        if (ch_number == "") {
            alert("请输入章节序号")
        }else if (writeMyLzName2input == "") {
            alert("请输入章节名称");
            return false;
        } else if (bAddress == "") {
            alert("请输入需发布章节内容");
            return false;
        } else {

            $.ajax({
                type: "post",
                url: "/cahpter/insertChapter",
                data: {
                    sId: sId,
                    ch_title:writeMyLzName2input,
                    ch_number:ch_number,
                    ch_address:bAddress
                },
                success: function (data) {
                    alert(data.msg);
                },
                error: function () {

                }

            });
        }
    });
    var E = window.wangEditor;
    var editor2 = new E('#div3');  // 两个参数也可以传入 elem 对象，class 选择器
    editor2.customConfig.zIndex = 0;
    editor2.customConfig.uploadImgServer = '/serialize/uploadBodyPicture';//上传URL
    editor2.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
    editor2.customConfig.uploadImgMaxLength = 5;
    editor2.customConfig.uploadFileName = 'myFileName';
    // editor1('editor1', { zIndex: 0});
    editor2.customConfig.uploadImgHooks = {
        customInsert: function (insertImg, result, editor1) {
            // 图片上传并返回结果，自定义插入图片的事件（而不是编辑器自动插入图片！！！）
            // insertImg 是插入图片的函数，editor 是编辑器对象，result 是服务器端返回的结果

            // 举例：假如上传图片成功后，服务器端返回的是 {url:'....'} 这种格式，即可这样插入图片：
            var url = result.data;
            insertImg(url);
            // result 必须是一个 JSON 格式字符串！！！否则报错
        }
    };
    editor2.create();


};